const baseurl = "http://qf.exam.698zq.com/";
import axios from 'axios'
import Qs from 'qs'
/*默认设置*/
const instance = axios.create({
    baseURL:baseurl,
    // headers: {'X-Custom-Header': 'foobar'},
})

let setToken = (data)=> {
   
    if (data) {    
        data['access_token'] = window.localStorage.Token;
        return data;
    }else {
        return {
            access_token:window.localStorage.Token
        }
    }
       
}

// 
const exams = {
    // 获取用户基本信息
    userinfo: (data,calback) => {
        return instance.post("index/user/info",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    // 考生/医生个人中心
    userinfo1: (data,calback) => {
        return instance.post("index/home/userinfo1",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    // 科秘书个人中心
    userinfo2: (data,calback) => {
        return instance.post("index/home/userinfo2",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    // 科主任个人中心
    userinfo3: (data,calback) => {
        return instance.post("index/home/userinfo3",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    // 获取考试试题题型
    questionlist: (data,calback) => {
        return instance.post("index/question/start",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    //发布考试通知
    noticepublish: (data,calback) => {
        return instance.post("index/notice/publish",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    //首次进入获取url的token请求获取对应身份
    getRole: (data,calback) => {
        return instance.post("index/token/getRole",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    //通知列表
    noticepageList: (data,calback) => {
        return instance.post("index/notice/pageList",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    //通知详情
    noticedetail: (data,calback) => {
        return instance.post("index/notice/detail",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    //单位属性迁移
    organizationmove: (data,calback) => {
        return instance.post("index/organization/move",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    // 获取考试试题题型（测试）
    questionlisttest: (data,calback) => {
        return instance.post("index/test/question",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    // 获取考试试题题型（正式）
    questionlistpaper: (data,calback) => {
        return instance.post("index/paper/start",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    //即将开始考试  列表
    cominglist: (data,calback) => {
        return instance.post("index/paper/coming",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    //判断当前试卷是否允许考试  列表
    iscanStart: (data,calback) => {
        return instance.post("index/paper/canStart",setToken(data)).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    //添加考生
    addExaminee: (data,calback) => {
        return instance.post("index/paper/addExaminee",Qs.stringify(setToken(data))).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    //历史记录
    answerrecordlist: (data,calback) => {
        return instance.post("index/answer/pageList",Qs.stringify(setToken(data))).then((res) => {
        	calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
    //添加考生
    paperSubmit: (data,calback) => {
        return instance.post("index/paper/submit",Qs.stringify(setToken(data))).then((res) => {
            calback('success',res)
        }).catch(error => {
            calback('error',error.response)
        })
    },
}

export default {baseurl,exams}